//字面量初始化
var colors = ["red": "#FF0000", "green": "#00FF00", "blue": "#0000FF"]

// 创建空字典
var emptyDict = [String: String]()
var emptyDict2 = [Int: String]()
var emptyDict1: [String: Double] = [:]

// 使用数组初始化
let keyValuePairs = [("a", 1), ("b", 2), ("c", 3)]
let dict = Dictionary(uniqueKeysWithValues: keyValuePairs)  // ["a": 1, "b": 2, "c": 3]
print(dict)

// 使用数组初始化-处理重复键
let keyValuePairsWithDuplicates = [("a", 1), ("b", 2), ("a", 3), ("c", 3)]
let dictWithDuplicates = Dictionary(
    keyValuePairsWithDuplicates, uniquingKeysWith: { (first, last) in last })  // 使用后面的值

// 从序列初始化
let names = ["Alice", "Bob", "Charlie"]
let namesLengths = Dictionary(uniqueKeysWithValues: names.map { ($0, $0.count) })
print("namesLengths:\(namesLengths)")
